package main

import (
	"github.com/micro/go-micro/v2"
	"github.com/micro/go-micro/v2/registry"
	"github.com/micro/go-plugins/registry/consul/v2"
	"gomicrodemo/changgou-user_service/handler"
	"gomicrodemo/changgou-user_service/mq"
	"gomicrodemo/common"
	"gomicrodemo/proto/user"
)

func main() {

	common.InitMq()
	go mq.InitSubcribe()

	//声明consul服务发现的ip端口
	consulRegistru := consul.NewRegistry(
		registry.Addrs("127.0.0.1:8500"))

	//创建一个微服务
	service := micro.NewService(
		micro.Name("go.micro.homin.user"),
		micro.Registry(consulRegistru),
	)

	service.Init()

	db := common.GetDB("go_mysql")

	//TODO 暴露接口到对应的微服务中,注册微服务，传入服务对象
	user.RegisterUserHandler(service.Server(), handler.NewUserHandler(db))


	if err := service.Run(); err != nil {
		panic(err)
	}

}
